package doublepointer;

/**
 * @Classname : ContainerWithMostWater
 * @Description : 11. 盛最多水的容器
 * https://leetcode.cn/problems/container-with-most-water/
 * @Author : chentianyu
 * @Date 2023/2/25 22:31
 */


public class ContainerWithMostWater {
    public int maxArea(int[] height) {
        int l = 0, r = height.length - 1, max = 0;
        while (l < r) {
            int h = Math.min(height[l], height[r]);
            int w = r - l;
            max = Math.max(max, h * w);
            // 博弈：只有高度较小的边向里移动，才有可能使容量增加
            if (height[l] < height[r]) l++;
            else r--;
        }
        return max;
    }
}
